﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Database;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace TareasService
{
    public class TaskService : ITaskService
    {
        public IEnumerable<Project> getProjects()
        {
            ProjectContext p = new ProjectContext();
            return p.Projects.AsEnumerable();
        }

        public IEnumerable<Task> getTasks(int proj)
        {
            ProjectContext p = new ProjectContext();
            return p.Tasks.Where(q => q.RelatedProject.ProjectId == proj).AsEnumerable();
        }

        public void addTask(Task t)
        {
            ProjectContext pc = new ProjectContext();
            t.RelatedProject = pc.Projects.Where(p => p.ProjectId == t.RelatedProject.ProjectId).First();
            pc.Tasks.Add(t);
            pc.SaveChanges();
        }

        public IEnumerable<Project> getProjectByName(string name) 
        {
            ProjectContext p = new ProjectContext();
            return p.Projects.Where(proj => proj.Name.Contains(name)).AsEnumerable();
        }
    }
}
